home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.1 KB | 133 lines | [TEXT/KAHL] |
- //------------------------- © 1992-1995 by James G. Stout --------------------------
- // File : dtcCDEF.h
- // Date : 20 June 1992
- // Author : Jim Stout
- // :
- // Purpose : a "Date Time Control" CDEF that allows adjustment of date
- // : and time as in the General Control Panel. Clicking on the
- // : date or time numerals will show a 'small arrow' type control for
- // : date or time adjustment. Since CDEF's don't get key events,
- // : this control does not respond to typing.
- //
- // : Also, since controls must be "self contained", mouse clicks
- // : on numbers select and de-select. Toggling the highlighting
- // : in a manner slightly different from the control panel which
- // : de-selects when you click outside the numbers (which would be
- // : outside the control).
- // :
- // : The control respects the settings from the Date & Time
- // : panel (mostly - it always displays leading zeros). It
- // : will use the user settings for date & time separators and
- // : format.
- // :
- // : By passing a non-zero contrlMax, you can force the time
- // : format to 24 hour format.
- // :
- // : By passing a non-zero contrlMin, a 3D variant is drawn.
- // :
- // : The Control RefCon should be set with a long word as
- // : returned from a "GetDateTime(&secs)" call. The control will
- // : adjust this value and it can be retrieved by the calling
- // : program with "GetCRefCon(theControl)" call. If you don't
- // : fill this in, the control will default the the current time.
- // :
- // : Use calls to SetControlValue to reset (no highlighting) or
- // : highlight numbers programatically.
- // :
- // : Valid control values (partCodes returned) to highlight
- // : specific numbers are :
- // :
- // : 2 hours
- // : 3 minutes
- // : 4 AM/PM
- // : 7 month (7,8,9 match user order from Control Panel
- // : 8 day and may not have these meanings)
- // : 9 year
- // :
- // : This control supports many variation codes, see the
- // : #defines below.
- // :
- // : use procID : 103 * 16 + varCode
- // : when calling NewControl() or in your resource template.
- //
- //----------------------------------------------------------------------------------
-
- #define ARROWHT 18 // the size of the arrows
- #define ARROWID 11
-
- //----------------------------------------------------------------------------------
- // variation codes
- //----------------------------------------------------------------------------------
-
- #define dateTime 0x00 // show both, date left, time right justified
- #define dateOnly 0x01 // show date, left justified in control rect
- #define timeOnly 0x02 // show time, right justified in control rect
- #define dtStack 0x04 // show both on 2 lines, date then time
- #ifndef useWindFont
- #define useWindFont 0x08 // draw with window font instead of System font
- #endif
- #define showAMPM 0x10 // an extended variation code, used internally
- #define ctl3D 0x20 // likewise
-
- //----------------------------------------------------------------------------------
- // partCodes - also returned as contrlValue to indicate hilited field
- //----------------------------------------------------------------------------------
-
- enum {
- ALL = 0,
- FRAMET,
- HOURS,
- MINUTES,
- AMPM,
- UPTIME,
- DOWNTIME,
- DT1,
- DT2,
- DT3,
- UPDATE,
- DOWNDATE,
- DATE,
- FRAMED,
- TITLE,
- FONTINFO,
- NUMPARTS
- };
-
- //----------------------------------------------------------------------------------
- // the dtcCDEF private data
- //----------------------------------------------------------------------------------
-
- typedef struct {
- CGrafPtr offPort; // offscreen drawing port
- PolyHandle poly[6]; // polgons for up/down arrows & frames
- short arrowHilite; // 0 = not hilited
- short varCode; // we need a bigger varCode than 4 bits…
- short qdVers; // QuickDraw version
- short pDepth; // pixel depth for control
- short currSel;
- char timeSep; // next 4 from the Intl0 record
- unsigned char timeCycle;
- unsigned char dateSep;
- unsigned char dateOrder;
- }dtcData,**dtcHandle;
-
- //----------------------------------------------------------------------------------
- // Function prototypes
- //----------------------------------------------------------------------------------
-
- static void doInit (ControlHandle theControl, short varCode);
- static void doDisp (ControlHandle theControl);
- static long doTest (ControlHandle theControl, short varCode, long param);
- static void doDraw (ControlHandle theControl, short varCode, short partCode);
- static void drawArrows (ControlHandle theControl, short varCode, short partCode,
- Boolean inColor);
- static void updateValue (ControlHandle theControl, short varCode, short partCode);
- static void doHilite (ControlHandle theControl, short varCode, short flag,
- Boolean backPat);
- static void getRects (ControlHandle theControl, short varCode, Rect r1[]);
- static void getTimeStr (ControlHandle theControl, short varCode, long secs, Str31 string);
- static void getDateFmt (ControlHandle theControl, short * m, short * d, short * y);
- static void getDateStr (ControlHandle theControl, long secs, Str31 string);
- static char arrowPart (short partCode);
- static void makePolys (ControlHandle theControl, short varCode);
-